<?php 
    session_start();
    include_once 'inc/db.class.php';
    include_once 'inc/function.php';
    $id=isset($_GET["id"]) ? $_GET["id"] : "";
    if($id==""){
        //header("location:index.php");
        echo "<script>history.go(-1);<script>";
    }
    //读取产品
    $sql="select * from goods where id=".$id;
    $rs=$db->getData($sql,true);
    //print_r($rs);
    //读取图片
    $sqlp="select * from goodspic where gid=".$id;
    $rsp=$db->getData($sqlp);
    //print_r($rsp); 
    //读取规格
    $sqls="select * from goodsspec where gid=".$id;
    $rss=$db->getData($sqls);
    
    //读取type=1的产品
    $sqlt="select goods.id,goods.price,goods.name,goodspic.pic from goods,goodspic where goods.id=goodspic.gid and goods.type=1 group by goods.id order by rand() limit 5";
    $rst=$db->getData($sqlt);
    //print_r($rs);
    
    //读取该商品评价
    $sqle="select * from eva where gid=".$id." limit 2";
    $rse=$db->getData($sqle);
    
    //读取评价数量 ，好评 中评，差评
    $sqlevacount="select count(-1) as c,evatype from eva where gid=".$id." group by evatype";
    $rsevacount=$db->getData($sqlevacount); 
    //print_r($rsevacount);
    //把评价的二维数据转换成为数组
    $evaarr=array();
    foreach ($rsevacount as $v){
        $evaarr[$v["evatype"]]=$v["c"];
    } 
    //print_r($evaarr); 
    $hp=isset($evaarr[0]) ? $evaarr[0] : 0;
    $zp=isset($evaarr[1]) ? $evaarr[1] : 0;
    $cp=isset($evaarr[2]) ? $evaarr[2] : 0;
    $qb=$hp+$zp+$cp;
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<?php include_once 'meta.php'; ?>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
		<link href="assets/css/admin.css" rel="stylesheet" type="text/css" />
		<link href="assets/css/amazeui.css" rel="stylesheet" type="text/css" />
		<link href="basic/css/demo.css" rel="stylesheet" type="text/css" />
		<link type="text/css" href="css/optstyle.css" rel="stylesheet" />
		<link type="text/css" href="css/style.css" rel="stylesheet" />

		<script src="http://www.5imoban.net/download/jquery/jquery.1.11.3.js"></script>
		<script type="text/javascript" src="basic/js/quick_links.js"></script>
        
		<script type="text/javascript" src="assets/js/amazeui.js"></script>
		<script type="text/javascript" src="js/jquery.imagezoom.min.js"></script>
		<script type="text/javascript" src="js/jquery.flexslider.js"></script>
		<script type="text/javascript" src="js/list.js"></script>
		<script src="distpicker/distpicker.data.js"></script>
	    <script src="distpicker/distpicker.js"></script>
        <script src="layer/layer.js"></script>
	</head>

	<body>


		 <?php include_once 'header1.php'; ?>

			<div class="clear"></div>
			<b class="line"></b>
           <div class="search">
			<div class="search-list">
			<div class="nav-table">
					   <?php include_once 'header2.php'; ?>
			</div>
			
				<ol class="am-breadcrumb am-breadcrumb-slash">
					<li><a href="index.php">首页</a></li>
					<li><a href="search.php">产品中心</a></li>
					<li class="am-active">产品详情</li>
				</ol>
				<script type="text/javascript">
					var specid;
					$(function() {});
					$(window).load(function() {
						$('.flexslider').flexslider({
							animation: "slide",
							start: function(slider) {
								$('body').removeClass('loading');
							}
						});
					});  
					$(function(){
						$(".sku-line").click(function(){
							//alert($(this).next().val());
							var price=$(this).attr("title");
							specid=$(this).attr("specid");
							$(".sys_item_price").text(price);
							
						});
					});


					$(document).ready(function(){
						var l1;
						$("#LikBasket").click(function(){
							//alert($(".guige").children().length);
							if($(".guige").children().length>0){
								if(specid==""){
    								layer.msg("请选择规格",{icon:5});
    								return;
								}
							}
							
							$.ajax({
								url:"ajax/addbasket.php",  
								type:"post",
								data:{"gid":<?php echo $id; ?>,"gnum":$("#text_box").val(),"specid":specid,"flag":0},	
								success:function(data){
									//alert(data);
									if(data==0){	
										
										 l1=layer.open({
										  type: 1,
										  title:'登登登登登录',
										  skin: 'layui-layer-rim', //加上边框
										  area: ['420px', '240px'], //宽高
										  content: "<div class='mylogin'>"+$("#loginpage").html()+"</div>",
										});
										 $(".am-btn-primary").bind("click",fun1);		
									}else if(data==1){
										layer.msg("非法订单",{icon:5});
									}else if(data==2){
										//购物车改为实时数量
										var a=parseInt($("#J_MiniCartNum").text());
										var b=parseInt($("#text_box").val());
										$("#J_MiniCartNum").text(a+b);
										$(".cart_num").text(a+b);
										layer.msg("添加成功",{icon:1});
									}else if(data==3){
										layer.msg("添加失败",{icon:5});
									}else{
										layer.msg("添加购物车失败",{icon:5});
									}
									
								},
								error:function(){
									layer.msg("系统故障",{icon:3});
								}
							});
						});
	//1111111				//弹出层绑定单击事件      		
						var fun1;
						$(".am-btn-primary").click(fun1=function(){
								var u=$(".mylogin #username").val();
								var p=$(".mylogin #userpwd").val();
								//alert(u+" "+p);

								//用正则判断格式是否正确
								var pre=/^[a-zA-Z0-9_]{5,18}$/;
								var pre2=/^1[3456789]\d{9}$/;
    							var pre3=/^[a-zA-Z0-9]+\@[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/;
								if(!pre.test(u) && !pre2.test(u) && !pre3.test(u)){
									layer.msg("用户格式错误",{icon:3});
									return;
								}
								if(!pre.test(p)){
									layer.msg("密码格式错误",{icon:3});
									return;
								}
								$.ajax({
									url:"ajax/login.php",
									type:"post",
									data:{"username":u,"userpwd":p},
									success:function(data){
										
										if(data==1){
											//关闭本窗口
											 
											layer.close(l1);
    										window.location.reload();
    									}else if(data==2){
    										layer.msg("用户名或者密码错误");
    									}else{
    										layer.msg("登录失败");
    									}
    								},
    								error:function(){
    									layer.msg("系统故障");	
    								}
    							});
    						});
						});
					
				</script> 
				<style>
				    #loginpage{
	                   display:none; 
				    }
                    #loginpage2>div{
				        text-align:center;
                        line-height:40px;  
				    }
				    
				</style>
                    <div id="loginpage">
                        <div id="loginpage2">
                            <div class="user-name">
                                <label for="user"><i class="am-icon-user"></i></label>
                                <input value="" type="text" name="username" id="username" placeholder="邮箱/手机/用户名">
                            </div>
                            <div class="user-pass">
                                <label for="password"><i class="am-icon-lock"></i></label>
                                <input type="password" name="userpwd" id="userpwd" placeholder="请输入密码">
                            </div>
                            <div class="am-cf">
                                <input type="submit" name="" id="login" value="登 录" class="am-btn am-btn-primary am-btn-sm">
                            </div>
                        </div>
                    </div>
				
				<div class="scoll">
					<section class="slider">
						<div class="flexslider">
							<ul class="slides">
								<li>
									<img src="images/01.jpg" title="pic" />
								</li>
								<li>
									<img src="images/02.jpg" />
								</li>
								<li>
									<img src="images/03.jpg" />
								</li>
							</ul>
						</div>
					</section>
				</div>

				<!--放大镜-->

				<div class="item-inform">
					<div class="clearfixLeft" id="clearcontent">

						<div class="box">
							<script type="text/javascript">
								$(document).ready(function() {
									$(".jqzoom").imagezoom();
									$("#thumblist li a").click(function() {
										$(this).parents("li").addClass("tb-selected").siblings().removeClass("tb-selected");
										$(".jqzoom").attr('src', $(this).find("img").attr("mid"));
										$(".jqzoom").attr('rel', $(this).find("img").attr("big"));
									});
								});
							</script>

							<div class="tb-booth tb-pic tb-s310">
								<a href="images/01.jpg"><img src="goodsimg/<?php echo $rsp[0]["pic"];  ?>" alt="细节展示放大镜特效" rel="goodsimg/<?php echo $rsp[0]["pic"];  ?>" class="jqzoom" /></a>
							</div>
							<ul class="tb-thumb" id="thumblist">
								<?php foreach ($rsp as $k=>$v){ ?>
								<li class="<?php if($k==0){echo "tb-selected";} ?>">
									<div class="tb-pic tb-s40">
										<a href="#"><img src="goodsimg/<?php echo $v["pic"];  ?>" mid="goodsimg/<?php echo $v["pic"];  ?>" big="goodsimg/<?php echo $v["pic"];  ?>"></a>
									</div>
								</li>
								<?php } ?>
							</ul>
						</div>

						<div class="clear"></div>
					</div>

					<div class="clearfixRight">

						<!--规格属性-->
						<!--名称-->
						<div class="tb-detail-hd">
							<h1>	
				<?php echo $rs["name"]; ?>
	          </h1>
						</div>
						<div class="tb-detail-list">
							<!--价格-->
							<div style="height:50px;padding-top:15px;" class="tb-detail-price">
								<li class="price iteminfo_price">
									<dt>促销价</dt>
									<dd><em>¥</em><b class="sys_item_price"><?php echo $rs["price"] ?></b>  </dd>                                 
								</li>
								
								<div class="clear"></div>
							</div>  

							<!--地址-->
							<dl class="iteminfo_parameter freight">
								<dt>配送至</dt>
								<div class="iteminfo_freprice">
								    <style>
                                        .form-group{
	                                           width:400px;
                                        }
                                     </style>
									 <div class="am-form-content address">
										<div data-toggle="distpicker">
                                           <div class="form-group">
                                              <label class="sr-only" for="province1">Province</label>
                                              <select class="form-control" id="province1"></select>
                                            </div>
                                            <div class="form-group">
                                              <label class="sr-only" for="city1">City</label>
                                              <select class="form-control" id="city1"></select>
                                            </div>
                                            <div class="form-group">
                                              <label class="sr-only" for="district1">District</label>
                                              <select class="form-control" id="district1"></select>
                                            </div>
                                        </div>
									</div>
									<div class="pay-logis">
										快递<b class="sys_item_freprice">10</b>元
									</div>
								</div>
							</dl>
							<div class="clear"></div>

							<!--销量-->
							<ul class="tm-ind-panel">
								<li class="tm-ind-item tm-ind-sellCount canClick">
									<div class="tm-indcon"><span class="tm-label">月销量</span><span class="tm-count">1015</span></div>
								</li>
								<li class="tm-ind-item tm-ind-sumCount canClick">
									<div class="tm-indcon"><span class="tm-label">累计销量</span><span class="tm-count">6015</span></div>
								</li>
								<li class="tm-ind-item tm-ind-reviewCount canClick tm-line3">
									<div class="tm-indcon"><span class="tm-label">累计评价</span><span class="tm-count">640</span></div>
								</li>
							</ul>
							<div class="clear"></div>

							<!--各种规格-->
							<dl class="iteminfo_parameter sys_item_specpara">
								<dt class="theme-login"><div class="cart-title">可选规格<span class="am-icon-angle-right"></span></div></dt>
								<dd>
									<!--操作页面-->

									<div class="theme-popover-mask"></div>

									<div class="theme-popover">
										<div class="theme-span"></div>
										<div class="theme-poptit">
											<a href="javascript:;" title="关闭" class="close">×</a>
										</div>
										<div class="theme-popbod dform">
											<form class="theme-signin" name="loginform" action="" method="post">

												<div class="theme-signin-left">

													<div class="theme-options">
														<div class="cart-title">规格</div>
														<ul class="guige">
														    <?php foreach ($rss as $v){ ?>
															<li title="<?php echo $v["price"] ?>" specid="<?php echo $v["id"]; ?>" class="sku-line"><?php echo $v["name"]; ?><i></i></li>
															<input type="hidden" class="sprcptice" value="<?php echo $v["price"]; ?>" />
															
															<?php } ?>
														</ul>
													</div>
													<div class="theme-options">
														<div class="cart-title number">数量</div>
														<dd>
															<input id="min" class="am-btn am-btn-default" name="" type="button" value="-" />
															<input id="text_box" name="" type="text" value="1" style="width:30px;" />
															<input id="add" class="am-btn am-btn-default" name="" type="button" value="+" />
															<span id="Stock" class="tb-hidden">库存<span class="stock"><?php echo $rs["num"]; ?></span>件</span>
														</dd>

													</div>
													<div class="clear"></div>

													<div class="btn-op">
														<div class="btn am-btn am-btn-warning">确认</div>
														<div class="btn close am-btn am-btn-warning">取消</div>
													</div>
												</div>
												<div class="theme-signin-right">
													<div class="img-info">
														<img src="images/songzi.jpg" />
													</div>
													<div class="text-info">
														<span class="J_Price price-now">¥39.00</span>
														<span id="Stock" class="tb-hidden">库存<span class="stock">1000</span>件</span>
													</div>
												</div>

											</form>
										</div>
									</div>

								</dd>
							</dl>
							<div class="clear"></div>
							<!--活动	-->
							<div class="shopPromotion gold">
								
								<div class="clear"></div>
								<div class="coupon">
									<dt class="tb-metatit">优惠券</dt>
									<div class="gold-list">
										<ul>
											<li>125减5</li>
											<li>198减10</li>
											<li>298减20</li>
										</ul>
									</div>
								</div>
							</div>
						</div>

						<div class="pay">
							<div class="pay-opt">
							<a href="home.html"><span class="am-icon-home am-icon-fw">首页</span></a>
							<a><span class="am-icon-heart am-icon-fw">收藏</span></a>
							
							</div>
							<li>
								<div class="clearfix tb-btn tb-btn-buy theme-login">
									<a id="LikBuy" title="点此按钮到下一步确认购买信息" href="#">立即购买</a>
								</div>
							</li>
							<li>
								<div class="clearfix tb-btn tb-btn-basket theme-login">
									<a id="LikBasket" title="加入购物车"  href="javascript:;"><i></i>加入购物车</a>
								</div>
							</li>
						</div>

					</div>

					<div class="clear"></div>

				</div>

				    
				<div class="clear"></div>
				
							
				<!-- introduce-->

				<div class="introduce">
					<div class="browse">
					    <div class="mc"> 
						     <ul>					    
						     	<div class="mt">            
						            <h2>看了又看</h2>        
					            </div>
						     	
							     <?php foreach ($rst as $v){ ?>	      
							      <li class="first">
							      	<div class="p-img">                    
							      		<a  href="introduction.php?id=<?php echo $v["id"]; ?>"> <img class="" src="goodsimg/<?php echo $v["pic"] ?>"> </a>               
							      	</div>     
							      	<div class="p-name"><a href="introduction.php?=<?php echo $v["id"]; ?>">
							      		<?php echo $v["name"]; ?>
							      	</a>
							      	</div>
							      	<div class="p-price"><strong>￥<?php echo $v["price"] ?></strong></div>
							      </li>							      
					               <?php } ?>
						     </ul>					
					    </div>
					</div>
					<div class="introduceMain">
						<div class="am-tabs" data-am-tabs>
							<ul class="am-avg-sm-3 am-tabs-nav am-nav am-nav-tabs">
								<li class="am-active">
									<a href="#">

										<span class="index-needs-dt-txt">宝贝详情</span></a>

								</li>

								<li>
									<a href="#">

										<span class="index-needs-dt-txt">全部评价</span></a>

								</li>

								    
							</ul>

							<div class="am-tabs-bd">

								<div class="am-tab-panel am-fade am-in am-active">
									<div class="J_Brand">

										<div class="attr-list-hd tm-clear">
											<h4>产品参数：</h4></div>
										<div class="clear"></div>
										<ul id="J_AttrUL">
											<li title="">产品类型:　<?php echo $rs["intro"]; ?></li>
											<li title="">原料产地:</li>
											<li title="">产地:</li>
											<li title="">配料表:</li>
											<li title="">产品规格:</li>
											<li title="">保质期:</li>
											<li title="">产品标准号:&nbsp;GB/T 22165</li>
											<li title="">生产许可证编号：&nbsp;QS4201 1801 0226</li>
											<li title="">储存方法： </li>
											<li title="">食用方法：   </li>
										</ul>
										<div class="clear"></div>
									</div>

									
									<div class="clear"></div>

								</div>

								<div class="am-tab-panel am-fade">
									
                                    <div class="actor-new">
                                    	<div class="rate">                
                                    		<strong><?php if($qb==0){
                                    		    echo 0;
                                    		}else{
                                    		    echo round($hp/($hp+$zp+$cp)*100,1);
                                    		} ?><span>%</span></strong><br> <span>好评度</span>            
                                    		
                                    	</div>
                                        <dl>                    
                                            <dt>买家印象</dt>                    
                                            <dd class="p-bfc">
                                            			<q class="comm-tags"><span>味道不错</span><em>(2177)</em></q>
                                            			<q class="comm-tags"><span>颗粒饱满</span><em>(1860)</em></q>
                                            			<q class="comm-tags"><span>口感好</span><em>(1823)</em></q>
                                            			<q class="comm-tags"><span>商品不错</span><em>(1689)</em></q>
                                            			<q class="comm-tags"><span>香脆可口</span><em>(1488)</em></q>
                                            			<q class="comm-tags"><span>个个开口</span><em>(1392)</em></q>
                                            			<q class="comm-tags"><span>价格便宜</span><em>(1119)</em></q>
                                            			<q class="comm-tags"><span>特价买的</span><em>(865)</em></q>
                                            			<q class="comm-tags"><span>皮很薄</span><em>(831)</em></q> 
                                            </dd>                                           
                                         </dl> 
                                    </div>	
                                    <div class="clear"></div>
									<div class="tb-r-filter-bar">
										<ul class=" tb-taglist am-avg-sm-4">
											<li class="tb-taglist-li tb-taglist-li-current">
												<div class="comment-info">
													<span>全部评价</span>
													<span class="tb-tbcr-num">(<?php echo $hp+$zp+$cp; ?>)</span>
												</div>
											</li>

											<li class="tb-taglist-li tb-taglist-li-1">
												<div class="comment-info">
													<span>好评</span>
													<span class="tb-tbcr-num">(<?php echo $hp; ?>)</span>
												</div>
											</li>

											<li class="tb-taglist-li tb-taglist-li-0">
												<div class="comment-info">
													<span>中评</span>
													<span class="tb-tbcr-num">(<?php echo $zp; ?>)</span>
												</div>
											</li>

											<li class="tb-taglist-li tb-taglist-li--1">
												<div class="comment-info">
													<span>差评</span>
													<span class="tb-tbcr-num">(<?php echo $cp; ?>)</span>
												</div>
											</li>
										</ul>
									</div>
									<div class="clear"></div>

									<ul class="am-comments-list am-comments-list-flip">
										<?php foreach ($rse as $v){ ?>
										<li class="am-comment">
											<!-- 评论容器 -->
											<a href="javasrcipt:;">
												<img class="am-comment-avatar" src="memberimg/<?php echo getmember($v["mid"],"pic"); ?>" />
												
											</a>

											<div class="am-comment-main">
											
												<header class="am-comment-hd">
													
													<div class="am-comment-meta">
														<!-- 评论元数据 -->
														<a href="#link-to-user" class="am-comment-author"<?php echo $v["mid"]; ?>></a>
														<!-- 评论者 -->
														评论于
														<time datetime=""><?php echo date("Y-m-d H:i:s", $v["evatime"]); ?></time>
													</div>
												</header>

												<div class="am-comment-bd">
													<div class="tb-rev-item " data-id="255776406962">
														<div class="J_TbcRate_ReviewContent tb-tbcr-content ">
															<?php echo $v["content"]; ?>
														</div>
														<div class="tb-r-act-bar">
															规格：<?php echo getspec($v["sid"]); ?>
														</div>
													</div>

												</div>
												<!-- 评论内容 -->
											</div>
										</li>
                                        <?php } ?>
									</ul>

									<div class="clear"></div>

									<!--分页 -->
									
									<div class="clear"></div>

									<div class="tb-reviewsft">
										<div class="tb-rate-alert type-attention">购买前请查看该商品的 <a href="#" target="_blank">购物保障</a>，明确您的售后保障权益。</div>
									</div>

								</div>

								 
							</div>

						</div>

						<div class="clear"></div>

						<?php include_once 'footer.php'; ?>
					</div>

				</div>
			</div>
			<!--菜单 -->
			<?php include_once 'aside.php'; ?>

	</body>

</html>